﻿using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    public partial class Email : BYFW.BOL.BaseEntity
    {
        public Email()
        {
            m_tableName = "t_email";
            m_tblCacheManager.IsEnable = true;
        }

        protected string m_subject = string.Empty;
        protected string m_content = string.Empty;
        protected string m_bcc = string.Empty;
        protected bool m_isSent = false;
        protected DateTime m_sendDate = DateTime.MaxValue;
        protected DateTime m_planSendDate = DateTime.MaxValue;
        protected DateTime m_requestDate = DateTime.Now;

        /// <summary>
        /// 标题
        /// </summary>
        public string Subject
        {
            get { return m_subject; }
            set { m_subject = value; }
        }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        {
            get { return m_content; }
            set { m_content = value; }
        }
        /// <summary>
        /// BCC列表
        /// </summary>
        public string Bcc
        {
            get { return m_bcc; }
            set { m_bcc = value; }
        }
        /// <summary>
        /// 是否发送
        /// </summary>
        public bool IsSent
        {
            get { return m_isSent; }
            set { m_isSent = value; }
        }
        /// <summary>
        /// 实际发送时间
        /// </summary>
        public DateTime SendDate
        {
            get { return m_sendDate; }
            set { m_sendDate = value; }
        }

        /// <summary>
        /// 计划发送时间
        /// </summary>
        public DateTime PlanSendDate
        {
            get { return m_planSendDate; }
            set { m_planSendDate = value; }
        }

        /// <summary>
        /// 邮件请求时间
        /// </summary>
        public DateTime RequestDate
        {
            get { return m_requestDate; }
            set { m_requestDate = value; }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("subject", m_subject);
            m_container.Add("content", m_content);
            m_container.Add("bcc", m_bcc);
            m_container.Add("isSent", m_isSent ? 1 : 0);
            m_container.Add("sendDate", m_sendDate);
            m_container.Add("planSendDate", m_planSendDate);
            m_container.Add("requestDate", m_requestDate);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_subject = this.GetStringValue(record, "subject");
            m_content = this.GetStringValue(record, "content");
            m_bcc = this.GetStringValue(record, "bcc");
            m_isSent = this.GetBoolValue(record, "isSent");
            m_sendDate = this.GetDateValue(record, "sendDate");
            m_planSendDate = this.GetDateValue(record, "planSendDate");
            m_requestDate = this.GetDateValue(record, "requestDate");
            return true;
        }

        /// <summary>
        /// 获取未发送的邮件
        /// </summary>
        /// <param name="catalogID"></param>
        /// <returns></returns>
        public List<Email> GetUnSentMail()
        {
            return this.GetSpecialList<Email>(null, "isSent", 0);
        }
    }
}